const gulp = require("gulp");
const connect = require("gulp-connect");
const uglify = require("gulp-uglify");
const cleanCss = require("gulp-clean-css");
const babel = require("gulp-babel");

gulp.task("cleanCss", done => {
    gulp.src("css/*")
        .pipe(cleanCss())
        .pipe(gulp.dest("dist/css"));

    done();
});

gulp.task("babel", done => {
    gulp.src("js/*.js")
        .pipe(babel({
            presets: ['@babel/preset-env']
        }))
        .pipe(uglify())
        .pipe(gulp.dest("dist/js"));
    done();
})

gulp.task("copyHtml",done=>{
    gulp.src("*.html").pipe(gulp.dest("dist"))
    .pipe(connect.reload());
    done();
})
gulp.task("copyImg",done=>{
    gulp.src("img/*").pipe(gulp.dest("dist/img"))
    .pipe(connect.reload());;
    done();
})
gulp.task("copyFont",done=>{
    gulp.src("font/*").pipe(gulp.dest("dist/font"))
    .pipe(connect.reload());;
    done();
})
gulp.task("copyJs",done=>{
    gulp.src("js/*").pipe(gulp.dest("dist/js"))
    .pipe(connect.reload());;
    done();
})
gulp.task("copyCss",done=>{
    gulp.src("css/*").pipe(gulp.dest("dist/css"))
    .pipe(connect.reload());;
    done();
})
gulp.task("watch",done=>{
    gulp.watch("*.html",gulp.series("copyHtml"))
    gulp.watch("*.css",gulp.series("copyCss"))
    gulp.watch("*.js",gulp.series("copyJs"))
    gulp.watch("*.img",gulp.series("copyImg"))
    gulp.src("font/*").pipe(gulp.dest("dist/font"))
    done();
})
gulp.task("server",done=>{
    connect.server({
        "root":"dist",
        livereload:true
    })
    done();
})
// gulp.task("build",gulp.parallel("copyHtml","copyCss","copyJs","copyFonts","copyImg","copyFont")); 
gulp.task("default",gulp.series("server","watch"));
